<template>
	<div class="app-container">
		<el-form class="queryForms" :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
			label-width="70px">
			<el-form-item label="工序编码" prop="processCode">
				<el-input maxlength="20" show-word-limit v-model="queryParams.processCode" placeholder="请输入工序编码"
					clearable @keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="工序名称" prop="processName">
				<el-input maxlength="20" show-word-limit v-model="queryParams.processName" placeholder="请输入工序名称"
					clearable @keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="工序状态" prop="processStatus">
				<el-select v-model="queryParams.processStatus">
					<el-option v-for="item in processStatusList" :key="item.id" :label="item.name" :value="item.id">
					</el-option>
				</el-select>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
				<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
			</el-form-item>
		</el-form>
		<el-row :gutter="10" class="mb8">
			<el-col :span="1.5">
				<el-button size="mini" type="info" @click="handleBacks">返回</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button size="mini">{{ $route.query.productName }}-{{ $route.query.productModel }} ( 产品编号：{{
					$route.query.productNumber }} )</el-button>
			</el-col>
			<right-toolbar @changeTableData="changeTableData" menuNames="menuList75" :showSearch.sync="showSearch"
				@queryTable="getList" :columns.sync="columns" perm="erp:taskFilling:list"></right-toolbar>
		</el-row>
		<div :class="sidebar.opened && eleTabTop <= 85 ? 'eleTab' : !sidebar.opened && eleTabTop <= 85 ? 'eleTabs' : ''"
			class="informationTab" ref="eleTab">
			<el-table ref="table" @row-click="row_click" v-loading="loading" :data="repairProductProcessList"
				@selection-change="handleSelectionChange" border height="100%">
				<el-table-column type="selection" width="55" align="center" />
				<el-table-column label="序号" align="center" type="index" width="55" />
				<!-- <el-table-column label="返修任务单" prop="repairNumber" min-width="150" :show-overflow-tooltip="true" v-if="columns[0].visible" /> -->
				<!-- <el-table-column label="工序编码" prop="processCode" min-width="150" :show-overflow-tooltip="true" v-if="columns[0].visible" /> -->
				<!-- <el-table-column label="产品名称" prop="productName" min-width="150" :show-overflow-tooltip="true" v-if="columns[3].visible" />
				<el-table-column label="产品型号" prop="productModel" min-width="150" :show-overflow-tooltip="true" v-if="columns[4].visible" />
				<el-table-column label="产品编号" prop="productNumber" min-width="150" :show-overflow-tooltip="true" v-if="columns[5].visible" />
				<el-table-column label="客户名称" prop="clientName" min-width="150" :show-overflow-tooltip="true" v-if="columns[6].visible" />
				<el-table-column label="客户代表" prop="productRepresentativeName" min-width="150" :show-overflow-tooltip="true" v-if="columns[7].visible" />
				<el-table-column label="3B号" prop="bNumber" min-width="150" :show-overflow-tooltip="true" v-if="columns[8].visible" />
				<el-table-column label="维修类别" prop="maintenanceCategoryName" min-width="150" :show-overflow-tooltip="true" v-if="columns[11].visible" />
				<el-table-column label="故障原因" prop="failureCause" min-width="150" :show-overflow-tooltip="true" v-if="columns[12].visible" />
				<el-table-column label="故障模式" prop="failureMode" min-width="150" :show-overflow-tooltip="true" v-if="columns[13].visible" />
				<el-table-column label="故障核实情况" align="center" prop="malfunctionStatus" min-width="150" :show-overflow-tooltip="true" v-if="columns[14].visible">
					<template slot-scope="scope">
						<div v-if="scope.row.malfunctionStatus == '0'">无故</div>
						<div v-if="scope.row.malfunctionStatus == '1'">有故</div>
						<div v-if="scope.row.malfunctionStatus == '2'">待核实</div>
					</template>
</el-table-column>
<el-table-column label="工艺通知单编号" prop="processNumber" min-width="150" :show-overflow-tooltip="true"
	v-if="columns[15].visible" />
<el-table-column label="工艺流名称" prop="productTechnologyName" min-width="150" :show-overflow-tooltip="true"
	v-if="columns[16].visible" /> -->
				<el-table-column label="计划开始时间" align="center" prop="technologyBeginTime" min-width="180"
					:show-overflow-tooltip="true" v-if="columns[0].visible" />
				<el-table-column label="计划完成时间" align="center" prop="technologyFinishTime" min-width="180"
					:show-overflow-tooltip="true" v-if="columns[1].visible" />
				<el-table-column label="工序名称" prop="processName" min-width="200" v-if="columns[2].visible">
					<template slot-scope="scope">
						<el-tooltip placement="right">
							<div slot="content" class="custom-tooltip-content">
								<div id="editorVal" v-html="scope.row.content"></div>
							</div>
							<div class="custom-tooltip-trigger">{{ scope.row.processName }}</div>
						</el-tooltip>
					</template>
				</el-table-column>
				<el-table-column label="工时" align="center" prop="processTime" min-width="150"
					:show-overflow-tooltip="true" v-if="columns[3].visible" />
				<el-table-column label="工序状态" align="center" prop="processStatus" min-width="150"
					:show-overflow-tooltip="true" v-if="columns[4].visible">
					<template slot-scope="scope">
						<div v-if="scope.row.processStatus == '0'">未完工</div>
						<div v-if="scope.row.processStatus == '1'">已完工</div>
						<div v-if="scope.row.processStatus == '2'">质检通过</div>
						<div v-if="scope.row.processStatus == '3'">质检不通过</div>
					</template>
				</el-table-column>
				<el-table-column label="操作" class-name="small-padding fixed-width custom-height" fixed="right"
					width="260">
					<template slot-scope="scope">
						<!-- <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row, 1)" v-hasPermi="['erp:taskFilling:edit']">导出{{ scope.row.processType == "1" ? "弹簧测力" : "探伤报告" }}</el-button> -->
						<el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row, 1)"
							v-hasPermi="['erp:taskFilling:edit']">修改工作单</el-button>
						<el-button v-if="scope.row.processStatus == '0' || scope.row.processStatus == '3'" size="mini"
							type="text" icon="el-icon-edit" @click="handleUpdate(scope.row, 2)"
							v-hasPermi="['erp:taskFilling:write']">填写工作单</el-button>
						<el-dropdown size="mini" @command="command => handleCommand(command, scope.row)"
							v-hasPermi="['erp:taskFilling:files', 'erp:taskFilling:details', 'erp:taskFilling:export']">
							<el-button size="mini" type="text" icon="el-icon-d-arrow-right">更多</el-button>
							<el-dropdown-menu slot="dropdown">
								<el-dropdown-item command="handleFiles"
									v-hasPermi="['erp:taskFilling:files']">附件</el-dropdown-item>
								<el-dropdown-item command="handleDetail"
									v-hasPermi="['erp:taskFilling:details']">详情</el-dropdown-item>
								<el-dropdown-item command="handleReset"
									v-hasPermi="['erp:taskFilling:reset']">重置工序</el-dropdown-item>
								<el-dropdown-item v-if="scope.row.processType" command="handleExport"
									v-hasPermi="['erp:taskFilling:export']">生成{{ scope.row.processType == "1" ? "弹簧测力" :
										"探伤报告" }}</el-dropdown-item>
							</el-dropdown-menu>
						</el-dropdown>
					</template>
				</el-table-column>
			</el-table>
		</div>
		<pagination menuNames="Pagination78" v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
			:limit.sync="queryParams.pageSize" @pagination="getList" />
		<!-- 添加或修改返修单产品工序列对话框 -->
		<el-dialog title="详情" :visible.sync="open" width="900px" append-to-body v-dialogDrag>
			<el-form ref="form" :model="form" :rules="rules" label-width="90px">
				<el-row :gutter="20">
					<el-col :span="12">
						<el-form-item label="工艺流名称" prop="productTechnologyName">
							<el-input v-model="form.productTechnologyName" placeholder="请输入工艺流名称" disabled />
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="工序编码" prop="processCode">
							<el-input v-model="form.processCode" placeholder="请输入工序编码" disabled />
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="工序名称" prop="processName">
							<el-input v-model="form.processName" placeholder="请输入工序名称" disabled />
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="工时" prop="processTime">
							<el-input v-model="form.processTime" placeholder="请输入工时" disabled />
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="完成人名称" prop="accomplishUserName">
							<el-input v-model="form.accomplishUserName" placeholder="请输入完成人名称" disabled />
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
		</el-dialog>
	</div>
</template>

<script>
import { replacement, list2, getRepairProductProcess, delRepairProductProcess, addRepairProductProcess, updateRepairProductProcess } from "@/api/taskFilling/repairProductProcess"
import { mapGetters } from "vuex"
import { getcolumn } from "@/api/selectList"
import searchStateMixin from "@/layout/mixin/searchStateMixin.js"
export default {
	name: "menuLists",
	computed: {
		...mapGetters(["sidebar"])
	},
	mixins: [searchStateMixin],
	data() {
		return {
			contentHtml: "",
			eleTabTop: 0, //表格容器距浏览器顶部距离
			processStatusList: [
				{
					id: "0",
					name: "未完工"
				},
				{
					id: "1",
					name: "已完工"
				},
				{
					id: "2",
					name: "质检通过"
				},
				{
					id: "3",
					name: "质检不通过"
				}
			],
			// 遮罩层
			loading: true,
			// 选中数组
			ids: [],
			// 非单个禁用
			single: true,
			// 非多个禁用
			multiple: true,
			// 显示搜索条件
			showSearch: true,
			// 总条数
			total: 0,
			// 返修单产品工序列表格数据
			repairProductProcessList: [],
			// 弹出层标题
			title: "",
			// 是否显示弹出层
			open: false,
			// 查询参数
			queryParams: {
				pageNum: 1,
				pageSize: 10,
				militaryStatus: 0,
				repairProductId: null,
				productProcessId: null,
				productTechnologyId: null,
				productTechnologyName: null,
				processCode: null,
				processName: null,
				processTime: null,
				content: null,
				processStatus: null,
				accomplishUserId: null,
				accomplishUserName: null,
				repairNumber: null
			},
			// 表单参数
			form: {},
			// 表单校验
			rules: {},
			// 列信息
			columns: [
				{ key: 0, label: `计划开始时间`, visible: true },
				{ key: 1, label: `计划完成时间`, visible: true },
				{ key: 2, label: `工序名称`, visible: true },
				{ key: 3, label: `工时`, visible: true },
				{ key: 4, label: `工序状态`, visible: true }
			],
			isActive: false,
			fillingId: ''
		}
	},
	created() {
		this.fillingId = this.$route.query.fillingId
		// this.getSize()
	},
	watch: {
		"$route.query": {
			handler(newQuery, oldQuery) {
				if (newQuery.fillingId) {
					if (newQuery.queryData && Object.keys(newQuery.queryData).length != 0) {
						this.queryParams = { ...this.queryParams, ...JSON.parse(newQuery.queryData) }
					}
					this.fillingId = this.$route.query.fillingId
					this.getSize()
				}
			},
			immediate: true, // 立即执行一次
			deep: true // 深度监听
		}
	},
	mounted() {
		this.$nextTick(() => {
			this.$refs.table.doLayout()
		})
		// 滚动条的获取
		this.handleScrollx()
		window.addEventListener("scroll", this.handleScrollx, true)
	},
	activated() {
		//  this.fillingId = this.$route.query.fillingId
		// this.getSize()
		//获取表格容器距页面头部的距离
		this.handleScrollx()
	},
	deactivated() {
		window.removeEventListener("scroll", this.handleScrollx, true)
	},
	methods: {
		getSize() {
			getcolumn({ pageName: "Pagination78" }).then(response => {
				this.queryParams.pageSize = response.data.length ? (response.data[0].limit ? response.data[0].limit : 10) : 10
				this.getList()
			})
		},
		// 单击表格行
		row_click(row, column, event) {
			if (column && column.label == "操作") {
				return
			} else {
				this.$refs.table.toggleRowSelection(row)
			}
		},
		changeTableData() {
			this.$nextTick(() => {
				this.$refs.table.doLayout()
			})
		},

		handleBacks() {
			// 关闭当前tab页签，打开新页签
			// const obj = { path: this.$route.path }
			this.$router.push({
				path: "/taskFilling/taskFilling_menu",
        query:{
            queryData:this.$route.query.queryData
        }
			})

			// const obj = { path: this.$route.path }
			// this.$tab.closePage(obj).then(() => {
			// 	this.$router.go(-1)
			// })
		},
		//获取表格容器距页面头部的距离
		handleScrollx() {
			this.eleTabTop = this.$refs.eleTab.getBoundingClientRect().top
		},
		// 更多操作触发
		handleCommand(command, row) {
			switch (command) {
				case "handleFiles":
					this.handleFiles(row)
					break
				case "handleDetail":
					this.handleUpdate(row, 3)
					break
				case "handleReset":
					this.handleReset(row)
					break
				case "handleExport":
					this.handleExport(row)
					break
				default:
					break
			}
		},
		handleExport(row) {
			this.download(`/data/processWord/spring/${row.id}`, {}, `${row.processType == "1" ? "弹簧测力报告" : "探伤报告"}_${new Date().getTime()}.docx`)
		},
		handleDetail(row) {
			getRepairProductProcess(row.id).then(res => {
				this.form = res.data
				this.open = true
			})
		},
		handleFiles(row) {
			this.$router.push({
				path: "/attachment/attachmentUpload",
				query: {
					TableId: row.id,
					typeId: 15,
					perm: "erp:taskFilling:files",
					paths: "/taskFilling/taskFill/menuList/index",
					queryParams: JSON.stringify(this.queryParams),
					militaryStatus: 0,
					repairProductId: row.repairProductId,
					fillingId: this.fillingId,
					productName: this.$route.query.productName,
					productModel: this.$route.query.productModel,
					productNumber: this.$route.query.productNumber
				}
			})
		},
		/** 查询返修单产品工序列列表 */
		getList() {
			this.loading = true
			this.queryParams.repairProductId = this.fillingId
			list2(this.queryParams).then(response => {
				response.rows.forEach(element => {
					const parser = new DOMParser()
					const pastedDoc = parser.parseFromString(element.content, "text/html")
					const inputs = pastedDoc.querySelectorAll("input")
					inputs.forEach(item => {
						if ((item.type == "text" && item.value == "true") || (item.type == "text" && item.value == "false")) {
							item.style.setProperty("color", "white")
							var serializer = new XMLSerializer()
							// 将文档对象转换为HTML字符串
							var htmlString = serializer.serializeToString(pastedDoc)
							var doc1 = parser.parseFromString(htmlString, "text/html")
							var ols1 = doc1.querySelectorAll("body")
							// 获取body元素内的HTML内容
							var bodyContent = ols1[0].innerHTML
							element.content = bodyContent
						}
					})
				})
				this.repairProductProcessList = response.rows
				this.total = response.total
				this.loading = false
			})
		},
		// 取消按钮
		cancel() {
			this.open = false
			this.reset()
		},
		// 表单重置
		reset() {
			this.form = {
				id: null,
				repairProductId: null,
				productProcessId: null,
				productTechnologyId: null,
				productTechnologyName: null,
				processCode: null,
				processName: null,
				processTime: null,
				content: null,
				processStatus: null,
				accomplishUserId: null,
				accomplishUserName: null,
				remark: null,
				repairNumber: null,
				updateTime: null
			}
			this.resetForm("form")
		},
		/** 搜索按钮操作 */
		handleQuery() {
			this.queryParams.pageNum = 1
			this.saveSearchState()
			this.getList()
		},
		/** 重置按钮操作 */
		resetQuery() {
			this.resetForm("queryForm")
			this.clearSearchCache()
			this.handleQuery()
		},
		// 多选框选中数据
		handleSelectionChange(selection) {
			this.ids = selection.map(item => item.id)
			this.single = selection.length !== 1
			this.multiple = !selection.length
		},
		/** 新增按钮操作 */
		handleAdd() {
			this.reset()
			this.open = true
			this.title = "添加返修单产品工序列"
		},
		/** 修改按钮操作 */
		handleUpdate(row, status) {
			// status   1修改   2 填写
			// let querys = {
			// 	id: row.id,
			// 	status: status,
			// 	repairProductId: row.repairProductId,
			// 	workshopSectionId: row.workshopSectionId,
			// 	technologyDictCode: row.technologyDictCode,
			// 	processType: row.processType,
			// 	processStatus: row.processStatus,
			// 	isWrite: 1
			// }
			// localStorage.setItem('WriteKey',JSON.stringify(querys))

			this.$router.push({
				path: "/taskFilling/taskFill/writeContent/index",
				query: {
					id: row.id,
					status: status,
					repairProductId: row.repairProductId,
					workshopSectionId: row.workshopSectionId,
					technologyDictCode: row.technologyDictCode,
					processType: row.processType,
					isWrite: 1,
					fillingId: this.fillingId,
					processStatus: row.processStatus,
					productName: this.$route.query.productName,
					productModel: this.$route.query.productModel,
					productNumber: this.$route.query.productNumber
				}
			})
		},
		handleReset(row) {
			this.$modal
				.confirm("是否确认重置工序？")
				.then(function () {
					return replacement(row.id)
				})
				.then(() => {
					this.getList()
					this.$modal.msgSuccess("重置成功")
				})
				.catch(() => { })
		},
		/** 提交按钮 */
		submitForm() { },
		/** 删除按钮操作 */
		handleDelete(row) {
			const ids = row.id || this.ids
			this.$modal
				.confirm("是否确认删除返修单产品工序数据项？")
				.then(function () {
					return delRepairProductProcess(ids)
				})
				.then(() => {
					this.getList()
					this.$modal.msgSuccess("删除成功")
				})
				.catch(() => { })
		}
	}
}
</script>
<style lang="scss" scoped>
// ::v-deep .el-tooltip__popper {
//   background-color: #3eaf7c !important; /* 自定义背景颜色 */
//   color: #ffffff !important; /* 自定义文本颜色 */
//   border-radius: 5px !important; /* 自定义边框圆角 */
//   padding: 10px 15px !important; /* 自定义内边距 */
//   font-size: 14px !important; /* 自定义字体大小 */
//   width: 800px !important;
// }
/* 覆盖箭头样式 */
/* 设置特定列的高度 */
.custom-height {
	line-height: 0;
	/* 移除行高 */
	padding: 0;
	/* 移除内边距 */
	height: 100% !important;
	/* 你想要的高度 */
}

.el-tooltip__popper .popper__arrow {
	border-color: transparent !important;
	/* 将箭头颜色设置为透明 */
}

.el-tooltip__popper .popper__arrow:after {
	border-color: transparent !important;
	/* 将箭头的伪元素颜色也设置为透明 */
}

.custom-tooltip-content {
	// color: white;
	color: #606266;
	background-color: #fff;
	padding: 1px;
	width: 760px;
	border-radius: 2px;
}

#editorVal {
	width: 760px !important;
	max-height: 500px !important;
	overflow-y: auto;
	font-size: 14px;

	::v-deep input[type="text"] {
		border: none;
		outline: none;
		border-bottom: 1px solid #666;
	}
}

::v-deep .el-table__fixed-header-wrapper .fixed-width {
	width: 260px !important;
}
</style>
